import redis

r = redis.Redis(
    host='192.168.88.11',
    port='6379',
    db=0
)

r.set('name', 'tom')
print(r.get('name'))
s = r.get('name')
print(s, str(s, encoding='utf8'))

r.setnx('gender', 'jurry')
print(r.get('gender'))
r.setex('title', 20, 'python')
print(r.get('title'))

r.hset('person', 'name', 'tom')
r.hset('person', 'age', 18)
r.hset('person', 'gender', 'boy')
print(r.hget('person', 'name'))
print(r.hget('person', 'age'), r.hget('person', 'gender'))
print(r.hgetall('person'))
dict01 = r.hgetall('person')
dict02 = {}
for key in dict01:
    print(key, dict01[key])
for key, value in dict01.items():
    print(key, value)
    key = str(key, encoding='utf-8')
    value = str(value, encoding='utf-8')
    dict02[key] = value
print(dict02)
print(dict02['name'])


r.close()
